function K_NS()
{
	function K_TreeItem()
	{
	}
	K_TreeItem.prototype.getProperty=function(name)
	{
		return this[name];
	}
	K_TreeItem.prototype.setProperty=function(name,value)
	{
		if(this[name]==value){return;}
		if(this.data)
		{
			var returnObj={returnValue:true};
			SFEvent.trigger(this.data,"itempropertywrite",[returnObj,this,name,value]);
			if(!returnObj.returnValue){return false;}
		}
		var beforeValue=this.getProperty(name);
		this[name]=value;
		if(this.data)
		{
			this.data.updateItem(this,name,value);
			this.addChangeFields(name,beforeValue,value);
			SFEvent.trigger(this.data,"afteritemupdate",[this,name,value]);
		}
		return true;
	}
	K_TreeItem.prototype.getProperty=function(name)
	{
		return this[name];
	}
	K_TreeItem.prototype.setProperty=function(name,value)
	{
		if(this[name]==value){return;}
		var returnObj={returnValue:true};
		if(this.data)
		{
		    SFEvent.trigger(this.data,"itempropertywrite",[returnObj,this,name,value]);
		}
		if(!returnObj.returnValue)
		{
			return false;
		}
		var beforeValue=this.getProperty(name);
		this[name]=value;
		this.data.updateItem(this,name,value);
		this.addChangeFields(name,beforeValue,value);
		return true;
	}
	K_TreeItem.prototype.addChangeFields=function(name,bValue,value)
	{
		if(!this.changedFields){this.changedFields={};}
		if(!this.changedFields[name]){this.changedFields[name]={};}
		this.changedFields[name].beforeValue=bValue;
		this.changedFields[name].afterValue=value;
	}
	K_TreeItem.prototype.update=function()
	{
		if(!this.changedFields){return;}
		var changedFields=this.changedFields;
		this.changedFields=null;
		SFEvent.trigger(this.data,"afteritemupdate",[this,changedFields]);
	}
	K_TreeItem.prototype.getFirstChild=function()
	{
		if(typeof(this.firstChild)=="undefined")
		{
			this.firstChild=this.data.getItemFirstChild(this);
		}
		return this.firstChild;
	}
	K_TreeItem.prototype.getParentItem=function()
	{
		return this.parentItem;
	}
	K_TreeItem.prototype.getPreviousSibling=function()
	{
		return this.previousSibling;
	}
	K_TreeItem.prototype.getNextSibling=function(autoUp)
	{
		if(typeof(this.nextSibling)=="undefined")
		{
			this.nextSibling=this.data.getItemNextSibling(this);
		}
		if(!this.nextSibling && autoUp)
		{
			var parent=this.getParentItem();
			if(parent)
			{
				return parent.getNextSibling(autoUp);
			}
		}
		return this.nextSibling;
	}
	K_TreeItem.prototype.getPreviousItem=function()
	{
		var item=this.getPreviousSibling();
		return item?item.getLastDescendant():this.getParentItem();
	}
	K_TreeItem.prototype.getNextItem=function()
	{
		if(this==this.data.rootItem){return this.getFirstChild();}//
		if(this.hasChild)
		{
			var item=this.getFirstChild();
			if(item){return item;}
		}
		var item=this.getNextSibling();
		if(item){return item;}
		for(var pItem=this.getParentItem();pItem;pItem=pItem.getParentItem())
		{
			item=pItem.getNextSibling();
			if(item){return item;}
		}
		return null;
	}
	K_TreeItem.prototype.getLastChild=function()
	{
		var lastChild=null;
		for(var child=this.getFirstChild();child;child=child.getNextSibling())
		{
			lastChild=child;
		}
		return lastChild;
	}
	K_TreeItem.prototype.getChildByIndex=function(index)
	{
		var child=this.getFirstChild();
		for(var i=0;i<index;i++)
		{
			if(!child){return child;}
			child=child.getNextSibling();
		}
		return child;
	}
	K_TreeItem.prototype.getLastDescendant=function(onlyView)
	{
		if(!this.hasChild || (onlyView && this.collapse)){return this;}
		var lastChild=this.getLastChild();
		return lastChild?lastChild.getLastDescendant(onlyView):this;
	}
	K_TreeItem.prototype.getNextViewItem=function()
	{
	    return this.collapse?this.getNextSibling(true):this.getNextItem();
	}
	K_TreeItem.prototype.getPreviousViewItem=function()
	{
		var t=this.getPreviousItem();
		if(!t || (this.previousSibling==t || p.parentItem==t)){return t;}
		var p,cp;
		while(p=t.getParentItem())
		{
			if(p.collapse)
			{
				cp=p;
			}
			if(p==this.previousSibling){break;}
		}
		return cp?cp:t;
	}
	K_TreeItem.prototype.containsItem=function(item)
	{
		for(var p=item;p;p=p.getParentItem())
		{
			if(p==this){return true;}
		}
		return false;
	}
	window.K_TreeItem=K_TreeItem;
}
K_NS();